package com.hqyj.cloudTest.controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.hqyj.cloudTest.service.CityService;
import com.hqyj.entity.Test.City;
import com.hqyj.entity.common.vo.Result;
import com.hqyj.entity.common.vo.Search;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * personal demo
 **/

@RestController
@RequestMapping("/api/test")
public class CityController {

    @Autowired
    private CityService cityService;


    @PostMapping(value = "/city", consumes = MediaType.APPLICATION_JSON_VALUE)
    public Result<City> insertCity(@RequestBody City city) {
        return cityService.insertCity(city);
    }


    //以表单格式传输到后端，以作示范，以作参考
    @PutMapping(value = "/city", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public Result<City> updateCity(@ModelAttribute City city) {
        return cityService.updateCity(city);
    }

    @DeleteMapping(value = "/city/{cityId}")
    public Result<Object> deleteCity(@PathVariable int cityId) {
        return cityService.deleteCity(cityId);
    }

    @GetMapping(value = "/city/{id}")
    public City selectCity(@PathVariable int id) {
        return cityService.selectCityById(id);
    }

    @PostMapping(value = "/cities",consumes = "application/json")
    public PageInfo<City> selectCitiesBySearch(@RequestBody Search search) {
        return cityService.getCitiesBySearch(search);
    }




}
